package designMode.exercise;

public class MyLinked {
	Node head = null;
	Node end = null;
	int size = 0;

	public MyLinked add(Object o) {
		size++;
		Node newNode = new Node(o);
		if (head == null) {
			head = newNode;
			end = head;
		} else {
			end.next = newNode;
			end = newNode;
		}
		return this;
	}

	public int size() {
		return size;
	}

	public String toString() {
		String str = "[";
		Node temp = head;
		for (int i = 0; i < size - 1; i++) {
			str += temp.o.toString() + ",";
			temp = temp.next;
		}
		str += end.o.toString() + "]";
		return str;
	}

	public static String str(int n) {
		String str = "";
		String longStr = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
		for (int i = 0; i < n; i++) {
			int x = (int) (Math.random() * 52);
			str += longStr.substring(x, x + 1);
		}
		return str;
	}

	public static void main(String[] args) {
		MyLinked ml = new MyLinked();
		for (int i = 0; i < 10; i++) {
			ml.add(str((int) (Math.random() * 5) + 1));
		}
		System.out.println(ml);
	}
}

class Node {
	Object o;
	Node next = null;

	public Node(Object o2) {
		o = o2;
	}

}
